package com.c.ctgproject.adapter.guang

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapter
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.entity.guang.MaterialChildListEntity
import com.c.ctgproject.utils.handlerNull

class MaterialChildSelectAdapter(private val context: Context, private val mList: List<MaterialChildListEntity.DataBean>, private val listener: MaterialChildSelectAdapter) : BaseEmptyRecyclerViewAdapterV2(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_material_child_select_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            val name = data.materialName.handlerNull()
            holder.mNameTV.text = if (name.isEmpty()) "异常数据请勿选择" else name
            holder.mNameTV.setOnClickListener {
                listener.onItemClick(position)
            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mNameTV: TextView = view.findViewById(R.id.mNameTV)
    }

    interface MaterialChildSelectAdapter {
        fun onItemClick(position: Int)
    }
}